<?php 
function zeronum($num){
	if(!is_numeric($num)){
		return false;
	}
	$num = explode('.',$num);
	$rl = $num[1];
	$int_part = sprintf("%09d",$num[0]);
	$i = 0;
	$rvalue='';
	while($i <= strlen($int_part)){
		$rvalue .= substr($int_part, $i, 3).',';
		$i = $i + 3;
	}
	$rvalue = substr($rvalue,0,strlen($rvalue)-2);
	$rvalue = explode(',',$rvalue);

	$rs=array();
	$null_url = base_url().'assets/img/null.png';
	$dot_url = base_url().'assets/img/dot.png';
	$dot_part='<img src="'.$dot_url.'" class="dot"/>';
	foreach ($rvalue as $value) {
		$part = '';
		if($value==0){
			for ($i=0;$i<3;$i++){
				$part.='<img src="'.$null_url.'" class="null"/>';
			}
		}else{
			for ($i=0;$i<3;$i++){
				$url = base_url().'assets/img/'.$value[$i].'.png';
				$part.='<img src="'.$url.'" class="num"/>';
			}
		}
		$rs[] = $part;
	}
	return implode($dot_part, $rs);
}

function create_default_avatar($uid){
	$uid = abs(intval($uid));
	$uid = sprintf("%09d", $uid);
	$dir1 = substr($uid, 0, 3);
	$dir2 = substr($uid, 3, 2);
	$dir3 = substr($uid, 5, 2);
	$info = array();
	$dir = BASEPATH.'data/avatars/'.$dir1.'/'.$dir2.'/'.$dir3.'/';
	$filename = substr($uid, -2).'_avatar';
	
	$avatar_org = $dir.$filename.'.jpg';
	$avatar_large = $dir.$filename.'_large.jpg';
	$avatar_middle = $dir.$filename.'_middle.jpg';
	$avatar_small = $dir.$filename.'_small.jpg';
	(!is_dir($dir))&&@mkdir($dir,0777,true);

	file_exists($avatar_org) && unlink($avatar_org);
	file_exists($avatar_large) && unlink($avatar_large);
	file_exists($avatar_middle) && unlink($avatar_middle);
	file_exists($avatar_small) && unlink($avatar_small);

	$default_source_small = BASEPATH.'assets/img/avatar_small.jpg';
	$default_source_middle = BASEPATH.'assets/img/avatar_middle.jpg';
	$default_source_large = BASEPATH.'assets/img/avatar_large.jpg';
	$default_source_orgin = BASEPATH.'assets/img/avatar_large.jpg';

	@copy($default_source_orgin, $avatar_org);
	@copy($default_source_small, $avatar_small);
	@copy($default_source_middle, $avatar_middle);
	@copy($default_source_large, $avatar_large);
}
?>